home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Text Capture FKEY / Text Capture source.cpt / My_EndUpdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-12  |  1.4 KB  |  57 lines  |  [TEXT/KAHL]

  1. #include "defs.h"
  2.  
  3. #include <Traps.h>
  4. #include "patching.h"
  5. Boolean TrapAvailable( short trapnum );
  6.  
  7. /*
  8.     The tricky thing here is that as the final step of the clean-up,
  9.     we want to deallocate the very handle containing this code.  It is
  10.     not safe for code to call DisposHandle on itself, since something
  11.     like the Zap dcmd may be running.  So we use a bit of trickery
  12.     involving the ToolScratch area in low memory, which I saw in someone
  13.     else's Notification Manager code.
  14. */
  15.  
  16. #define        ToolScratch        0x09CE    // an 8-byte scratch area in low memory
  17.  
  18. pascal void My_EndUpDate( void )
  19. {
  20.     WindowPtr    the_window;
  21.     
  22.     asm {
  23.         HEAD_PATCH_HEADER( EndUpDate )
  24.         move.L        8(A6), the_window
  25.     }
  26.     
  27.     if (the_window == front)
  28.     {
  29.         End_copy();        // finish and clean up
  30.         asm {
  31.                 LEA        @save_h, A0            ; Copy this code's handle...
  32.                 move.L    my_h, (A0)            ; ...into @save_h
  33.                 move.L    #ToolScratch, A0    ; Copy disposal code...
  34.                 move.L    @dispos, (A0)
  35.                 move.W    @rts, 4(A0)            ; ...into ToolScratch
  36.         }
  37.         if (TrapAvailable(_HWPriv))
  38.             FlushInstructionCache();
  39.         asm {
  40.                 movem.L    (SP)+, A0-A5/D0-D7    ; restore registers
  41.                 unlk    A6
  42.                 move.L    @0, -(SP)            ; push real EndUpdate address
  43.                 move.L    @save_h, -(SP)        ; push handle to dispose
  44.                 move.L    #ToolScratch, -(SP)    ; push address of ToolScratch
  45.                 RTS                            ; go to ToolScratch
  46.  
  47.     @save_h        dc.L    0
  48.     @dispos        move.L    (SP)+, A0
  49.                 DisposHandle
  50.     @rts        RTS
  51.         }
  52.     }
  53.     
  54.     asm {
  55.         HEAD_PATCH_FINISH
  56.     }
  57. }